﻿using System;
using System.Drawing;
using System.Windows.Forms;
using dk.Helper.Base;

namespace dk.Helper.Controls
{
    public partial class AddPlayerForm : Form
    {
        private readonly IWorld world;

        public AddPlayerForm(IWorld world)
        {
            this.world = world;
            SolidBrush = new SolidBrush(Color.White);
            InitializeComponent();
            btnColor.BackColor = SolidBrush.Color;
        }

        public IPlayer Player { get; private set; }

        public SolidBrush SolidBrush { get; private set; }

        private void txtAllyTag_TextChanged(object sender, EventArgs e)
        {
            lstPlayers.Items.Clear();
            string txtPlayerNameToLower = txtPlayerName.Text.ToLower();
            foreach (string playerName in world.Players.PlayersByName.Keys)
            {
                if (playerName.ToLower().Contains(txtPlayerNameToLower))
                {
                    lstPlayers.Items.Add(playerName);
                }
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Player = lstPlayers.SelectedItem == null
                         ? null
                         : world.Players.PlayersByName[lstPlayers.SelectedItem.ToString()];
        }

        private void btnColor_Click(object sender, EventArgs e)
        {
            if (colorDialog.ShowDialog() == DialogResult.OK)
            {
                btnColor.BackColor = colorDialog.Color;
                SolidBrush = new SolidBrush(colorDialog.Color);
            }
        }
    }
}